﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FCTC_Web.Models;
using FCTC_Web.DAL;
using FCTC_Web.Utilities;
using DAL;

namespace FCTC_Web.Controllers.Maintains
{
    public class TeamMemberController : Controller
    {
        //[Authorize]
        public ViewResult Index(int? pageId)
        {
            return View("Index", Pager6.Ins.GetPage<TeamMember>(pageId));
        }

        [HttpPost]
        public ActionResult Edit(TeamMember teamMember)
        {

            if (ModelState.IsValid)
            {
                CH.Edit<TeamMember>(teamMember);
                var pageId = Pager6.Ins.GetPageId<TeamMember>(teamMember.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(teamMember);
        }


        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            CH.Delete<TeamMember>(id);
            return RedirectToAction("Index");
        }

        [HttpPost]
        public ActionResult Create(TeamMember teamMember)
        {
            if (ModelState.IsValid)
            {
                teamMember.UpdateTime = DateTime.Now;
                teamMember.UpdatedUser = HttpContext.User.Identity.Name;
                CH.Create<TeamMember>(teamMember);
                var pageId = Pager6.Ins.GetPageId<TeamMember>(teamMember.ID);
                return RedirectToAction("Index", new { pageId = pageId });
            }
            return View(teamMember);
        }

        public ViewResult Details(int? id)
        {
            TeamMember teamMember = CH.GetDataById<TeamMember>(id);
            return View(teamMember);
        }

        public ActionResult Create()
        {
            return View();
        }



        public ActionResult Edit(int? id)
        {
            return View(CH.GetDataById<TeamMember>(id));
        }



        public ActionResult Delete(int? id)
        {
            TeamMember teamMember = CH.GetDataById<TeamMember>(id);
            return View(teamMember);
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }
    }
}